home *** CD-ROM | disk | FTP | other *** search
/ Macromedia Multimedia Showcase 5.1 / Macromedia - Multimedia Showcase 5.1 (Macromedia) (1996).ISO / pc / media / shared.dir / 02123_Script_Scrolling Text Object < prev    next >
Text File  |  1996-03-28  |  8KB  |  225 lines

  1. -- script for "Scrolling Text Object"
  2.  
  3. property scrollingTextChannel, scrollTop, scrollBottom, scrollHeight, ¼
  4.           sliderHeight, sliderTop, sliderBottom, sliderLoc, ¼
  5.           scrollUpButtonSprite, scrollDownButtonSprite, scrollSliderSprite, ¼
  6.           defaultVoff, maxVoff, sliderRange, maxTop, theScrollBarSprite
  7.  
  8. global gNavObj
  9.  
  10. on birth me, textChannel
  11.   -- The various buttons (up, down, and slider) are added dynamically, based
  12.   --   on the location of the slider bar.  The text is presumed to be in 
  13.   --   channel 6, unless another channel is specified.  The top mask should
  14.   --   be in channel 16, and the bottom mask in channel 17.  If these masks
  15.   --   are not found, then the bottom and top of the scroll buttons will be
  16.   --   used to determine top and bottom of scrollable areas.
  17.   
  18.   global sBirthPtr, tBirthPtr, sDeathPtr, tDeathPtr, castIdPtr, scriptPtr
  19.   
  20.   set scrollHeight = 0
  21.   set scrollSliderSprite = 0
  22.   set defaultVoff = 5
  23.   set maxVoff = 40
  24.   set buttonList = [ "bUp", "bDown", "bDrag" ]
  25.   set scriptList = [ "doScrollTextUp", "doScrollTextDown", "doSlideText" ]
  26.   if textChannel = "" or voidP(textChannel) or textChannel = 0 then
  27.     set scrollingTextChannel = 6
  28.   else
  29.     set scrollingTextChannel = value(textChannel)
  30.   end if
  31.   set scrollUpButtonSprite = 30
  32.   set scrollDownButtonSprite = 31
  33.   set scrollSliderSprite = 32
  34.   set myEvent = string( the curEvent of gNavObj )
  35.   set birthScene = item sBirthPtr of myEvent
  36.   put birthScene into item sDeathPtr of myEvent
  37.   put "end" into item tDeathPtr of myEvent
  38.   repeat with buttonNum = 1 to count(buttonList)
  39.     put getAt(buttonList,buttonNum) into item castIdPtr of myEvent
  40.     -- the #Instant causes a response on mouseDown, instead of on mouseUp
  41.     put (getAt(scriptList,buttonNum) && "#Instant") into item scriptPtr of myEvent
  42.     -- put " in scrolling text object"
  43.     DrawBtn (gNavObj, myEvent, "#AddScrollingText")
  44.   end repeat
  45.   return me
  46. end birth
  47.  
  48. on kill me
  49.   puppetSprite scrollingTextChannel, FALSE
  50.   if scrollSliderSprite > 0 then puppetSprite scrollSliderSprite,FALSE
  51.   set scrollHeight = 0
  52.   set scrollingTextChannel = 0
  53. end kill
  54.  
  55. --
  56.  
  57. on InitScrollingText me
  58.   if scrollingTextChannel = 0 then
  59.     return -1
  60.   end if
  61.   set scrollBarOffset = 16
  62.   puppetsprite scrollingTextChannel, TRUE
  63.   set scrollHeight = the height of cast (the castNum of sprite scrollingTextChannel)
  64.   set myTopMaskSprite = the topMaskSprite of gNavObj
  65.   set myBottomMaskSprite = the bottomMaskSprite of gNavObj
  66.   set topMaskCast = the castNum of sprite myTopMaskSprite
  67.   set bottomMaskCast = the castNum of sprite myBottomMaskSprite
  68.   set firstBtn = the firstBtnSprite of gNavObj
  69.   set lastBtn = the lastBtnSprite of gNavObj
  70.   if topMaskCast = 0 then
  71.     set topMaskCast = the castNum of sprite scrollUpButtonSprite
  72.     set myTopMaskSprite = scrollUpButtonSprite
  73.   end if
  74.   if bottomMaskCast = 0 then
  75.     set bottomMaskCast = the castNum of sprite scrollDownButtonSprite
  76.     set myBottomMaskSprite = scrollDownButtonSprite
  77.   end if
  78.   if scrollSliderSprite > 0 then puppetSprite scrollSliderSprite,TRUE
  79.   set scrollTop = the bottom of sprite myTopMaskSprite
  80.   set scrollBottom = the top of sprite myBottomMaskSprite
  81.   set theScrollBarSprite = the scrollBarSprite of gNavObj
  82.   set maxTop = scrollBottom - scrollHeight
  83.   set sliderRange = scrollTop - maxTop
  84.   set sliderHeight = the height of sprite theScrollBarSprite - (scrollBarOffset * 2)
  85.   set sliderTop = the top of sprite theScrollBarSprite + scrollBarOffset
  86.   set sliderBottom = the bottom of sprite theScrollBarSprite - scrollBarOffset
  87.   set sliderLoc = 0
  88. end InitScrollingText
  89.  
  90. --
  91. on doScrollTextUp
  92.   if objectP(the scrollingTextObj of gNavObj) then ScrollTextUp(the scrollingTextObj of gNavObj)
  93.   else put "no scrollingTextObj"
  94. end doScrollTextUp
  95.  
  96. on ScrollTextUp me
  97.   if scrollHeight = 0 then InitScrollingText(me)
  98.   set textSprite = scrollingTextChannel
  99.   if textSprite > 0 then
  100.     Unhilite(gNavObj)
  101.     set mySprite = the clickOn
  102.     set vOff = 10
  103.     set currentTop = (the top of sprite textSprite)
  104.     if (currentTop + vOff) > scrollTop then
  105.       set vDelta = scrollTop - currentTop
  106.     else
  107.       set vDelta = vOff
  108.     end if
  109.     set the locV of sprite textSprite = the locV of sprite textSprite + vDelta
  110.     updateSlider(me)
  111.     set startTimeDown = the ticks
  112.     repeat while the mouseDown
  113.       if rollover(mySprite) then
  114.         set currentTop = (the top of sprite textSprite)
  115.         if (currentTop + vOff) > scrollTop then
  116.           set vDelta = scrollTop - currentTop
  117.         else
  118.           set vDelta = vOff
  119.         end if
  120.         set the locV of sprite textSprite = the locV of sprite textSprite + vDelta
  121.         updateSlider(me)
  122.       end if
  123.       if vOff < maxVoff then
  124.         set halfSecsDown = ((the ticks - startTimeDown) / 30) + 1
  125.         set vOff = defaultVOff * halfSecsDown
  126.         if vOff > maxVoff then set vOff = maxVoff
  127.       end if
  128.     end repeat
  129.     set the timingOut of gNavObj = FALSE
  130.   end if
  131. end ScrollTextUp
  132.  
  133. --
  134. on doScrollTextDown
  135.   if objectP(the scrollingTextObj of gNavObj) then ScrollTextDown(the scrollingTextObj of gNavObj)
  136.   else put "no scrollingTextObj"
  137. end doScrollTextUp
  138.  
  139. on ScrollTextDown me
  140.   if scrollHeight = 0 then InitScrollingText(me)
  141.   set textSprite = scrollingTextChannel
  142.   if textSprite > 0 then
  143.     Unhilite(gNavObj)
  144.     set mySprite = the clickOn
  145.     set vOff = defaultVoff
  146.     set currentBottom = (the bottom of sprite textSprite)
  147.     if (currentBottom - vOff) < scrollBottom then
  148.       set vDelta = currentBottom - scrollBottom
  149.     else
  150.       set vDelta = vOff
  151.     end if
  152.     set the locV of sprite textSprite = the locV of sprite textSprite - vDelta
  153.     updateSlider(me)
  154.     set startTimeDown = the ticks
  155.     repeat while the mouseDown
  156.       if rollover(mySprite) then
  157.         set currentBottom = (the bottom of sprite textSprite)
  158.         if (currentBottom - vOff) < scrollBottom then
  159.           set vDelta = currentBottom - scrollBottom
  160.         else
  161.           set vDelta = vOff
  162.         end if
  163.         set the locV of sprite textSprite = the locV of sprite textSprite - vDelta
  164.         updateSlider(me)
  165.       end if
  166.       if vOff < maxVoff then
  167.         set halfsecsDown = ((the ticks - startTimeDown) / 30) + 1
  168.         set vOff = defaultVOff * halfSecsDown
  169.         if vOff > maxVoff then set vOff = maxVoff
  170.       end if
  171.     end repeat
  172.     set the timingOut of gNavObj = FALSE
  173.   end if
  174. end ScrollTextDown
  175.  
  176. --
  177.  
  178. on updateSlider me
  179.   if scrollSliderSprite > 0 then
  180.     updateStage
  181.     set curTop = the top of sprite scrollingTextChannel
  182.     set percentDown = 100 - (((curTop - maxTop) * 100) / sliderRange)
  183.     set sliderVloc = sliderTop + ((sliderHeight * percentDown) / 100)
  184.     set the locV of sprite scrollSliderSprite = sliderVloc
  185.     updateStage
  186.   end if
  187. end updateSlider
  188.  
  189. --
  190. on doSlideText
  191.   if objectP(the scrollingTextObj of gNavObj) then SlideText(the scrollingTextObj of gNavObj)
  192. end doScrollTextUp
  193.  
  194. on SlideText me
  195.   if scrollHeight = 0 then InitScrollingText(me)
  196.   set textSprite = scrollingTextChannel
  197.   set scrollFactor = (float(sliderRange) / sliderHeight)
  198.   if textSprite > 0 then
  199.     Unhilite(gNavObj)
  200.     set mySprite = the clickOn
  201.     set oldV = the locV of sprite mySprite
  202.     set offsetFromTop = (the top of sprite scrollingTextChannel - maxTop)
  203.     set maxTextRegV = (the locV of sprite scrollingTextChannel - offsetFromTop)
  204.     repeat while the mouseDown
  205.       if rollover(theScrollBarSprite) or rollover(mySprite) ¼
  206.                 or rollover(scrollDownButtonSprite) or rollover(scrollUpButtonSprite) then
  207.         set newV = the mouseV
  208.         if newV < sliderTop then
  209.           set newV = sliderTop
  210.         else
  211.           if newV > sliderBottom then set newV = sliderBottom
  212.         end if
  213.         set the locV of sprite mySprite = newV
  214.         set newSliderPixelsUp = sliderBottom - newV
  215.         set textOffsetV = (newSliderPixelsUp * scrollFactor)
  216.         set newTextV = maxTextRegV + TextOffsetV
  217.         set the locV of sprite scrollingTextChannel = newTextV
  218.         updateStage
  219.         set oldV = newV       
  220.       end if
  221.     end repeat
  222.     set the timingOut of gNavObj = FALSE
  223.   end if
  224. end KillScrollingText
  225.